<?php
/**
 * Celebrio Core
 * 
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    Celebrio
 * @subpackage Core
 */
namespace Celebrio\Core;

use Nette\Object;
use Nette\Environment;

use Celebrio\Core\CriticalException;

use Celebrio\AccessControl\AclConstants;

use dibi;

/**
 * Critical features
 *
 * @author pavel
 */
abstract class CriticalFeatures extends Object {
    
    /**
     * Check whether there is any problem which may cause Critical mode.
     * 
     * @throws CriticalException where any problem occurs
     */
    public static function check() {
        self::checkDatabaseConnection();
        self::checkBasicAcl();
    }
    
    private static function checkDatabaseConnection() {
        if (!dibi::isConnected()) {
            throw new CriticalException("Database connection has not been set up yet.");
        }
    }
    
    /**
     * For now, just checks whether there are ANY records in ACL table.
     */
    private static function checkBasicAcl() {
        $count = dibi::select("id")->from("acl")->count();
        if ($count == 0) {
            throw new CriticalException("There are no ACL records in DB.");
        }
    }
    
}

